<?php

namespace My\Controller;

use Utuo\BackgroundController;

class HouseTypeController extends BackgroundController {
	public function _initialize() {
		$this->setControllerTitle('3D看房');
		$this->setActionTitle(array(
				'index' => '户型列表',
				'add' => '添加户型',
				'modify' => '修改户型',
				'recycle' => '回收站' 
		));
		
		$this->setActionNav('index,add,recycle');
	}
	
	// 楼盘列表
	public function indexAction() {
		$this->getHouseTypeList(0);
	}
	
	// 楼盘回收站
	public function recycleAction() {
		$this->getHouseTypeList(1);
	}
	
	// 获取楼盘列表
	private function getHouseTypeList($is_deleted) {
		$dHouseType = D('HouseType');
		$condition = array(
				'cid' => $this->aid,
				'is_deleted' => $is_deleted 
		);
		$this->houseTypeLists = $dHouseType->where($condition)->order('id DESC')->select();
		$this->display();
	}
	
	// 添加楼盘
	public function addAction() {
		C("TOKEN_ON", true);
		$dHouseType = D('HouseType');
		$houseType = array();
		$houseType['status'] = $this->getRadio('status', $dHouseType->status, 1);
		$this->assign('houseType', $houseType);
		$this->display('save');
	}
	
	// 修改楼盘
	public function modifyAction() {
		$dHouseType = D('HouseType');
		$houseType = $dHouseType->find($this->getId());
		$houseType['status'] = $this->getRadio('status', $dHouseType->status, $houseType['status']);
		$this->assign('houseType', $houseType);
		$this->display('save');
	}
	
	// 保存楼盘
	public function saveAction() {
		$dHouseType = D('HouseType');
		$dHouseType->submit() !== false && $this->ajaxSuccess();
		$this->ajaxError($dHouseType->getError());
	}
	
	// 设置状态
	public function setStatusAction() {
		$this->ajaxSetStatus('HouseType');
	}
	
	// 移除
	public function removePostAction(){
		$this->ajaxRemove('HouseType');
	}
	
	// 恢复
	public function restorePostAction(){
		$this->ajaxRestore('HouseType');
	}
	
	// 删除
	public function deletePostAction(){
		$this->ajaxDelete('HouseType');
	}
}